package com.ml.mall.bean.res.product;

import com.ml.mall.entity.deduct.SysADeduct;
import com.ml.mall.service.deduct.SysADeductService;
import com.ml.mall.utils.OrderPriceUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

/**
 * Created by kyyang on 2021/5/22 16:46
 */
@Data
@Slf4j
//todo：商店数据
public class SysProductShopPageRes {

    private Long id;

    private Long variantId;

    private String variantName;

    private String picUrl;

    private BigDecimal price;
    private BigDecimal commissionRate;  //单个商品提成价格:如果有；售价以此来计算；
    private BigDecimal salesPrice; //促销价；是否有 没有就空

    private String   salesRate;  //优惠百分比 直接字符 "-10.00%"

    private String uom;     //单位

    private Integer moq;           //最小购买量 minOrder

    private Boolean haveCoupon;    //是否有优惠券；

    private String supplierCode ;  // 卖家编码； 不是名称 是编码
    private Long companyId ;  // 卖家id

    private Integer starsNum;    //卖家星级

    private String statesId;  //卖家洲名

    private Integer deliveryDay; //送达天数

    private Long productId;     //用于搜索关联产品

    private Integer quality;        //仅收藏夹查询使用

    /**
     * 计算提成之后的价格
     * @param
     * @return void
     * @author Daizh
     * @date 2021/9/10 10:53
     */
    public void changePrice(SysADeduct curDeduct) {
        BigDecimal deductRate = BigDecimal.ZERO;
        Integer type = 0;
        if (null != curDeduct) {
            deductRate = curDeduct.getDeductRate();
            type = curDeduct.getCentType();
        }
        //计算提成：溢出价全部在原价的基础上
        BigDecimal increasMoney = this.commissionRate==null?this.price.multiply(deductRate):this.price.multiply(this.commissionRate);
        if (null != this.salesPrice) {
//            //使用单独抽成还是系统抽成
//            BigDecimal increasMoney = this.commissionRate==null?this.salesPrice.multiply(deductRate):this.salesPrice.multiply(this.commissionRate);
            this.salesPrice = this.salesPrice.add(increasMoney).setScale(2, BigDecimal.ROUND_HALF_DOWN);;
            this.salesPrice = OrderPriceUtils.getOrderPriceByCentType(type,  this.salesPrice);
        }
        this.price = this.price.add(increasMoney).setScale(2, BigDecimal.ROUND_HALF_DOWN);
        this.price = OrderPriceUtils.getOrderPriceByCentType(type, this.price);
    }

}
